<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../static/教师端.css">
    <link rel="stylesheet" href="../static/iconfont/iconfont.css">
    <title>删除课程</title>
</head>
<body>
<div class="head">
    <div class="header">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<img width=36 height=36 src="../static/xh.png"/><img width=180 height=36 src="../static/wz.png"/>
        <a href="/teacher/login" class="exit"><i class="iconfont icon-tuichu"></i>退出登录</a></div>
</div>
<div class="big_box">
    <div class="wrap">
        <div class="seg"></div>
        <div class="item_title">
            <b>教师端</b>
        </div>
        <div class = "seg"></div>
        <div class="item">
            <a href="http://localhost:8080/teacher/tutorial"><i class="iconfont icon-yixuan" ></i>&ensp;任教课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/up_course"><i class="iconfont icon-fabu" ></i>&ensp;发布课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/modify_course"><i class="iconfont icon-xiugai" ></i>&ensp;修改课程</a>
        </div>
        <div class="item">
            <a href="http://localhost:8080/teacher/delete_course"><i class="iconfont icon-shanchu" ></i>&ensp;删除课程</a>
        </div>
        <div class="item">
            <a href="教师个人信息"><i class="iconfont icon-gerenxinxi" ></i>&ensp;个人信息</a>
        </div>
    </div>
    <div class="main">
        <div class="row">
            <h1>
                删除课程
            </h1>
            <div class="selected">
                <form action="/delete_search" method="post" >
                    请选择类别&nbsp;
                    <select id="classification" class="classification" onchange=selected() style="color: #295287;">
                        <option value="1-1">公共课</option>
                        <option value="1-2">专业课</option>
                        <option value="2-1">通识课</option>
                    </select>
                    <input type="button" class="button" value="检索" onclick="search()" />
                </form>
            </div>
            <div class="course_table" id="course_table">
                <table class="table" >
<!--                    <thead>-->
<!--                    <tr>-->
<!--                        <th>课程号</th>-->
<!--                        <th>课程名</th>-->
<!--                        <th>课程时长</th>-->
<!--                        <th>课程学分</th>-->
<!--                        <th>上课时间</th>-->
<!--                        <th>上课地点</th>-->
<!--                        <th>可选人数</th>-->
<!--                        <th>课程类别</th>-->
<!--                        <th>授课教师</th>-->
<!--                        <th>操作</th>-->
<!--                    </tr>-->
<!--                    </thead>-->
<!--                    <tbody>-->
<!--                    <tr th:each="Course:${course}">-->
<!--                        <td th:text="${Course.course_id}"></td>-->
<!--                        <td th:text="${Course.course_name}"></td>-->
<!--                        <td th:text="${Course.course_length}"></td>-->
<!--                        <td th:text="${Course.course_score}"></td>-->
<!--                        <td th:text="${Course.course_time}"></td>-->
<!--                        <td th:text="${Course.course_classroom}"></td>-->
<!--                        <td th:text="${Course.course_count}"></td>-->
<!--                        <td th:text="${Course.course_classification}"></td>-->
<!--                        <td th:text="${Course.course_teacher}"></td>-->
<!--                        <td><button  class="button2" onclick="Delete()">删除</button></td>-->
<!--                    </tr>-->
<!--                    </tbody>-->
                </table>
            </div>
        </div>
    </div>
    <div class="modal" id="myModal" style="display: none;">
        <div class="modal-dialog">
            <form class="modal-content"  method="post" id="Form" role="form">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" onclick="Default()">
                        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                </div>
                <div class="modal-body">
                    <h4 class="modal-title">确定删除<input placeholder="课程名" type="text" id="course_name" class="input"/>这门课吗？</h4>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn_default" data-dismiss="modal" onclick="Default()">取消</button>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
                    <button id="besure" type="button" class="btn_primary" onclick="Delete(this)">确定</button>
                </div>
            </form>
        </div>
    </div>
</div>
</div>
<script>
    function  Default() {
        document.getElementById("myModal").style.display="none";
    }
    function selected(){
        var vs=$('select option:selected').val();
    }
    function search(){
        var select=document.getElementById("classification");
        var classify=select.value;
        $.ajax({
                type: "POST",
                url: "/teacher/ututorial",
                data:{"classify_id":classify},
                dataType: "json",
                success: function (dat) {
                    if(dat.c_count==0) {
                        var ltr = '<tr><th>您暂未发布此类课程!</th></tr>';
                        $("table").empty();
                        $("table").append(ltr);
                    }
                    //  window.location.href="http://localhost:8080/teacher/tutorial";
                    else{
                        var ltr='<tr><th>'+"课程号"+
                            '</th><th>'+"课程名"+
                            '</th><th>'+"课程时长"+
                            '</th><th>'+"课程学分"+
                            '</th><th>'+"上课时间"+
                            '</th><th>'+"上课地点"+
                            '</th><th>'+"可选人数"+
                            '</th><th>'+"课程类别"+
                            '</th><th>'+"授课老师"+
                            '</th><th>'+"学期"+
                            '</th><th>'+"操作"+
                            '</th></tr>';
                        var course_th=dat.course_th;
                        $.each(course_th,function(index,course){
                            var term;
                            if(course.term=="1"){term="大一上学期"}
                            else if(course.term=="2"){term="大一下学期"}
                            else if(course.term=="3"){term="大二上学期"}
                            else if(course.term=="4"){term="大二下学期"}
                            else if(course.term=="5"){term="大三上学期"}
                            else if(course.term=="6"){term="大三下学期"}
                            var tr='<tr><td>'+course.courseid+
                                '</td><td>'+course.coursename+
                                '</td><td>'+course.coursetime+
                                '</td><td>'+course.coursescore+
                                '</td><td>'+course.time+
                                '</td><td>'+course.site+
                                '</td><td>'+course.number+
                                '</td><td>'+course.classify+
                                '</td><td>'+course.teacher+
                                '</td><td>'+term+
                                '</td><td><button id="'+course.courseid+'" value="'+course.coursename+
                                '" class="button" style="background-color:#308ad9;border: 3px solid #308ad9;" onclick="show_delete(this)">删除</button></td></tr>';
                            ltr=ltr+tr;
                            //document.getElementById("button_s").value=course.courseid;
                        })
                        $("table").empty();
                        $("table").append(ltr);
                    }
                },
                error : function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log("错误");
                    // 状态码
                    console.log(XMLHttpRequest.status);
                    // 状态
                    console.log(XMLHttpRequest.readyState);
                    // 错误信息
                    console.log(textStatus);
                }
            }
        )

    }
    function show_delete(self){
        document.getElementById("myModal").style.display="block";
        var course_name=$(self).val();
        var id=$(self).attr("id");
        $("#course_name").val(course_name);
        $("#besure").attr("id",id);
    }
    function Delete(self){
        var id=$(self).attr("id");
        $.ajax({
            type:"POST",
            url:"/teacher/udelete_course",
            dataType:"text",
            data:{
                "courseid":id
            },
            success:function(){
                alert("删除成功！");
              //  document.getElementById("myModal").style.display="none";
                window.location.reload();
            },
            error : function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("错误");
                // 状态码
                console.log(XMLHttpRequest.status);
                // 状态
                console.log(XMLHttpRequest.readyState);
                // 错误信息
                console.log(textStatus);
            }
        })
    }
    function logout() {
        $.ajax({
            async:false,
            type:"post",
            url:'/logout',
            contentType:"application/x-www-form-urlencoded;charset=utf-8",
            dataType:"text",
            complete:function(){
                window.location.reload();
            }
        })

    }
</script>
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/dist/js/bootstrap.min.js"></script>
<!-- Just to make our placeholder images work. Don't actually copy the next line! -->
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/vendor/holder.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.24/assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>